<template>
    <div v-show="showModal" class="fullscreenModalBox">
        <div class="van-header">人员列表
            <van-icon class="closeIcon" name="cross" size="16" @click="showModal = false;" />
        </div>
        <!-- 查询条件 -->
        <van-row class="search-row">
            <van-search v-model="formData.keyword" shape="round" maxlength="20" label="" placeholder="姓名 / 手机号" @search="onRefresh"></van-search>
        </van-row>
        <!-- 列表 -->
        <van-row class="listCon">
            <van-pull-refresh class="pullRefresh" v-model="refreshLoading" @refresh="onRefresh">
                <van-list v-model="loading" :finished="finished" :finished-text="listData.length ? '没有更多了' : ''" @load="onLoad">
                    <van-swipe-cell v-for="val in listData" :key="val.staffId">
                        <div class="cellContent" @click="handleChoose(val)">
                            <div class="icon">
                                <van-icon name="checked" color="#4eb3e9" v-if="staffId === val.staffId" />
                                <span v-else class="other"></span>
                            </div>
                            <p class="tit">
                                <span>{{ val.name }}</span>
                                <a v-show="val.gender === '1'">男</a>
                                <a v-show="val.gender === '2'" class="girl">女</a>
                            </p>
                            <p>
                                <span class="label">单位：</span>
                                {{ val.corpName }}
                            </p>
                            <p>
                                <span class="label">部门：</span>
                                {{ val.deptFullName }}
                            </p>
                        </div>
                    </van-swipe-cell>
                </van-list>
                <van-empty v-if="!loading && !listData.length" class="custom-image" :image="require('../../../../assets/images/empty.png')" description="暂无数据" />
            </van-pull-refresh>
        </van-row>
    </div>
</template>

<script>
    import { queryStaffByKeyword } from '@/api/platframe/orgUser/orgUser';
    export default {
        data () {
            return {
                showModal: false,
                loading: false,
                finished: false,
                refreshLoading: false,
                formData: {
                    keyword: '',
                    pageNum: 1,
                    pageSize: 20
                },
                listData: [],
                staffId: ''
            }
        },
        methods: {
            handleInit (staffId) {
                this.staffId = staffId;
                this.showModal = true;
                if (this.formData.keyword) {
                    this.formData.keyword = '';
                    this.onRefresh();
                } else if (!this.listData.length) {
                    this.onRefresh();
                }
            },
            // 获取列表数据
            getListData () {
                if (this.formData.keyword && !this.$commonReg.textReg.test(this.formData.keyword)) {
                    this.$Notify({ type: "warning", message: `搜索内容${this.$commonReg.textMsg}` });
                    return;
                }
                this.loading = true;
                queryStaffByKeyword(this.formData).then((res) => {
                    this.loading = false;
                    if (res.code === 1000 && res.data) {
                        this.listData = [...this.listData, ...res.data.records];
                        if (this.listData.length >= res.data.total) {
                            this.finished = true;
                        }
                    } else {
                        this.finished = true;
                    }
                }).catch(() => {
                    this.loading = false;
                    this.finished = true;
                });
            },
            onRefresh () {
                this.refreshLoading = false;
                this.finished = false;
                this.listData = [];
                this.formData.pageNum = 1;
                this.getListData();
            },
            onLoad () {
                this.formData.pageNum++;
                this.getListData();
            },
            // 选中人员
            handleChoose (item) {
                this.staffId = item.staffId;
                this.$emit('sendStaff', item);
                setTimeout(() => {
                    this.showModal = false;
                }, 250)
            },
        },
    };
</script>

<style lang="less" scoped>
    .fullscreenModalBox {
        position: fixed;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        z-index: 999;
        background: white;
        .van-header {
            height: 46px;
            padding: 0 15px;
            box-sizing: border-box;
            border-bottom: 1px solid #eee;
            background: #f9f9f9;
            line-height: 46px;
            font-size: 15px;
            text-align: center;
            position: relative;
            .closeIcon {
                color: #aaa;
                position: absolute;
                right: 10px;
                top: 15px;
            }
        }
        .listCon {
            height: calc(100% - 100px);
            overflow: auto;
            .cellContent {
                padding: 12px 12px 12px 45px;
                box-sizing: border-box;
                position: relative;
                font-size: 13px;
                line-height: 25px;
                .tit {
                    font-size: 15px;
                    line-height: 30px;
                    a {
                        background: rgb(70, 172, 240);
                        font-size: 9px;
                        color: #fff;
                        margin-left: 8px;
                        padding: 2px 5px;
                        border-radius: 3px;
                    }
                    .girl {
                        background: #f198a8;
                    }
                }
                .icon {
                    position: absolute;
                    left: 14px;
                    top: 19px;
                    .van-icon {
                        font-size: 19px;
                    }
                    .other {
                        display: inline-block;
                        width: 15px;
                        height: 15px;
                        border: 1px solid #aaa;
                        border-radius: 50%;
                    }
                }
            }
        }
    }
</style>
